from flask import Flask, request, jsonify
import random
from http import HTTPStatus
# 建议dashscope SDK 的版本 >= 1.14.0
from dashscope import Generation
messages = [{'role': 'system', 'content': 'You are a helpful assistant.'}]
app = Flask(__name__)
@app.route('/taskindex/newsindex', methods=['POST'])
def get_response():
    # 获取用户输入的消息
    messages.append({'role': 'user', 'content':  request.get_json().get('message')})
    # 调用Dashscope SDK的call函数生成回复内容
    response = Generation.call(model="qwen-turbo",
                                api_key="sk-3c0aee84e5b74dfcb5e36b4b1679a97e",  # 替换为你的API密钥
                               messages=messages,
                               # 将输出设置为"message"格式
                          result_format='message')
    messages.append({'role': 'assistant', 'content': response['output']['choices'][0]['message']['content']}) 
    return response

if __name__ == '__main__':
    app.run(debug=True)  # 启动Flask服务